
export function forEachChild(node: Node, fn: (child: Node) => void, recursion = false) {

    var childNodes: NodeList = node.childNodes;
    var childNodesLength: number = childNodes.length;

    // Iterate over all children (can be nodes or text content)
    for (var i: number = 0; i < childNodesLength; i++) {
        var child: Node = childNodes[i] || childNodes.item(i);

        // 是否递归
        if (recursion) {
            forEachChild(child, fn, recursion);
        }

        // Skip text content
        if (child.nodeType !== 1) continue;

        // Callback for child node
        fn(child);
    }
}
